﻿using UnityEngine;
using UnityEngine.UI;
using QFramework;
using HKTools;

/// <summary>
/// 与 NodeJsServer 服务器端通信功能模块，用户注册测试页面
/// </summary>
public class TestUI_RegisterPanel : MonoBehaviour, IController
{
    public IArchitecture GetArchitecture()
    {
        return HK_ArchitectureProvider.Architecture;
    }

    [Header("注册信息填入部分：")]
    [SerializeField] InputField username_Input;
    [SerializeField] InputField pwd_Input;
    [SerializeField] InputField rePwd_Input;
    [SerializeField] InputField realName_Input;

    [Header("注册按钮：")]
    [SerializeField] Button register_Btn;

    void Start()
    {
        register_Btn.onClick.AddListener(() => OnClickRegisterBtn());
    }

    // 点击 注册按钮
    void OnClickRegisterBtn()
    {
        if (username_Input.text == "" || pwd_Input.text == "" || rePwd_Input.text == "" || realName_Input.text == "")
        {
            Debug.Log("用户名或密码为空！请重新输入");
            return;
        }

        if (pwd_Input.text != rePwd_Input.text)
        {
            Debug.Log("密码不一致，请重新输入");
            return;
        }

        string username = username_Input.text;
        string password = pwd_Input.text;
        string realName = realName_Input.text;

        // 用户的注册信息
        var registerInfo = new RegisterInfo(username, password, realName);

        this.GetSystem<IHK_LoginRegisterSystem>().PostRegisterMsg(registerInfo, RegisterCallback);
    }

    void RegisterCallback(bool isSuccessed)
    {
        if (isSuccessed)
            Debug.Log("新用户注册成功");
        else
            Debug.Log("新用户注册失败");
    }
}
